import numpy as np

def foot_of_perpendicular(A, B, C):
    """
    计算点C到直线AB的垂足坐标
    参数:
        A, B: 直线上的两点坐标，格式 (x, y)
        C: 直线外一点坐标，格式 (x, y)
    返回:
        垂足坐标 (x, y)
    """
    # 解包坐标
    Ax, Ay = A
    Bx, By = B
    Cx, Cy = C
    # 计算向量AB和AC
    ABx = Bx - Ax
    ABy = By - Ay
    ACx = Cx - Ax
    ACy = Cy - Ay
    # 计算点积和模的平方
    dot_product = ABx * ACx + ABy * ACy
    len_sq = ABx * ABx + ABy * ABy
    # 处理直线两点重合的情况
    if len_sq == 0:
        return A  # 或B，因为两点重合
    # 计算投影比例参数t
    t = dot_product / len_sq
    # 计算垂足坐标
    Px = Ax + t * ABx
    Py = Ay + t * ABy
    direction = np.array(C) - np.array([Px, Py])
    length = np.linalg.norm(direction)
    #unit_direction = direction/length
    return direction,length